﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using SdmxMl.Common;

namespace SdmxMl.UC
{
    public partial class ComboMultiLines : UserControl
    {
        private MultiLang ml;
        private UcMlTextMultiLines ucml;
        public MultiLang ML
        {
            get 
            {
                return ml; 
            }
            set 
            { 
                if (value != null)
                    ml = value;
                ucml.ML = ml;
                if (ml == null)
                {
                    customComboBox1.Text = string.Empty;
                    
                    richTextBox1.Text = string.Empty;
                }
                else
                {
                    richTextBox1.Text = ml.ToString();
                }

                IsFinal = _isFinal == false ? false : true;
            }
        }

        private bool _isFinal;
        
        public bool IsFinal
        {
            get
            {
                return _isFinal;
            }

            set
            {
                _isFinal = value;
                customComboBox1.IsFinal = _isFinal;
                richTextBox1.ReadOnly = _isFinal;
                if (ucml != null)
                    ucml.IsFinal = _isFinal;
            }
        }
        
        public ComboMultiLines()
        {
            InitializeComponent();
            ucml = new UcMlTextMultiLines();
            customComboBox1.DropDownControl = ucml;
        }

        private void customComboBox1_DropDown(object sender, EventArgs e)
        {
            customComboBox1.Text = this.richTextBox1.Text;
        }

        private void customComboBox1_DropDownClosed(object sender, EventArgs e)
        {
            this.richTextBox1.Text = customComboBox1.Text;

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (ml != null)
            {
                ml.UpdateForCurrentLanguage(richTextBox1.Text);
                Text = customComboBox1.Text = this.richTextBox1.Text;
            }

        }

        public override string Text
        {
            get
            {
                return base.Text;
            }
            set
            {
                base.Text = value;
            }
        }

        private void richTextBox1_LinkClicked(object sender, LinkClickedEventArgs e)
        {
            try
            {
                System.Diagnostics.Process.Start(e.LinkText);
            }
            catch { }
        }
    }
}
